//
//  AppDelegate.m
//  Mideleague_Shop
//
//  Created by Zhiwang on 2020/5/22.
//  Copyright © 2020 Zhiwang. All rights reserved.
//

#import "AppDelegate.h"
#import "LKTabbarControllerConfig.h"
#import "LKTabbarViewController.h"
#import "LKSwitchRootVcTool.h"
#import "LaunchIntroductionView.h"
#import "LKDefineFile.h"
#import <iflyMSC/iflyMSC.h>

#import <JPush/JPUSHService.h>
// iOS10注册APNs所需头文件

//#define pushAppkey @"eda9a06ff04e87e13f24a30d"


#define pushAppkey @"59d0eaacec1f0b278ac79b2b"
#define APPID_VALUE           @"5d9ff58d"
//#define pushAppkey @"3c3c1fd37c2d622b673b52e1"

#ifdef NSFoundationVersionNumber_iOS_9_x_Max
#import <UserNotifications/UserNotifications.h>
#endif

@interface AppDelegate ()

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
    [LKSwitchRootVcTool switchRootController];
    [self.window makeKeyAndVisible];
    [application.delegate.window makeKeyAndVisible];
//    // 注册APNS
//    [self initAPNS];
//    // 初始化push
//    [self initPush:launchOptions];
//
//    // 注册通知
//    [[NSNotificationCenter defaultCenter] addObserver:self
//                                             selector:@selector(networkDidReceiveMessage:)
//                                                 name:kJPFNetworkDidReceiveMessageNotification
//                                               object:nil];
//    //初始化讯飞语音合成
//    //Set log level
//    [IFlySetting setLogFile:LVL_ALL];
//
//    //Set whether to output log messages in Xcode console
//    [IFlySetting showLogcat:YES];
//
//    //Set the local storage path of SDK
//    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
//    NSString *cachePath = [paths objectAtIndex:0];
//    [IFlySetting setLogFilePath:cachePath];
//
//    //Set APPID
//    NSString *initString = [[NSString alloc] initWithFormat:@"appid=%@",APPID_VALUE];
//
//    //Configure and initialize iflytek services.(This interface must been invoked in application:didFinishLaunchingWithOptions:)
//    [IFlySpeechUtility createUtility:initString];
    NSArray *images = @[@"1",@"2",@"3", @"4"];
    LaunchIntroductionView *launch = [LaunchIntroductionView sharedWithImages:images buttonImage:@"" buttonFrame:CGRectMake(120, HEIGHT - 50, WIDTH - 240, 40)];
    launch.currentColor = yellowDefaultColor;
    launch.nomalColor = [UIColor greenColor];
    return YES;
}
/*极光推送的通知事件的初始化*/
/**
 设置推送事件
 */

// 接收到通知事件
//- (void)networkDidReceiveMessage:(NSNotification *)notification {
//    NSDictionary *userInfo = [notification userInfo];
//    NSLog(@"接受到的信息数据%@",userInfo);
////    [LKPushSetModel setNewTagsWithInfo:userInfo];
//}


//- (void)initAPNS
//{
//    //Required
//    if ([[UIDevice currentDevice].systemVersion floatValue] >= 10.0) {
//        JPUSHRegisterEntity * entity = [[JPUSHRegisterEntity alloc] init];
//        if (@available(iOS 10.0, *)) {
//            entity.types = UNAuthorizationOptionAlert|UNAuthorizationOptionBadge|UNAuthorizationOptionSound;
//        } else {
//            // Fallback on earlier versions
//        }
//        [JPUSHService registerForRemoteNotificationConfig:entity delegate:self];
//    }
//    else if ([[UIDevice currentDevice].systemVersion floatValue] >= 8.0) {
//        //可以添加自定义categories
//        [JPUSHService registerForRemoteNotificationTypes:(UIUserNotificationTypeBadge |
//                                                          UIUserNotificationTypeSound |
//                                                          UIUserNotificationTypeAlert)
//                                              categories:nil];
//    }
//}

//- (void)initPush:(NSDictionary *)launchOptions
//{
//    // notice: 2.1.5版本的SDK新增的注册方法，改成可上报IDFA，如果没有使用IDFA直接传nil
//    // 如需继续使用pushConfig.plist文件声明appKey等配置内容，请依旧使用[JPUSHService setupWithOption:launchOptions]方式初始化。
//    [JPUSHService setupWithOption:launchOptions appKey:pushAppkey
//                          channel:nil
//                 apsForProduction:NO
//            advertisingIdentifier:nil];
//}
//
//- (void)applicationWillEnterForeground:(UIApplication *)application {
////    [JPUSHService setBadge:0];
////    [[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
//     [[NSNotificationCenter defaultCenter] postNotificationName:
//    @"initSocket"object:nil];
//}
//// 当应用在前台运行中，收到远程通知时，会回调这个方法。
//- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
//
//    [JPUSHService handleRemoteNotification:userInfo];
//}
//
//#pragma mark - 通知相关
//#pragma mark 在前台接受到通知会调用 / 当应用在后台状态时，点击push消息启动应用 (ios10在前台接收到不会调用)
//- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
//    // 取得 APNs 标准信息内容
//
//    //BOOL isActive;
//    if (application.applicationState == UIApplicationStateActive) {
//        //  isActive = YES;
//    } else {
//        //  isActive = NO;
//        [self jumpToOther:userInfo];
//    }
//
//    [JPUSHService handleRemoteNotification:userInfo];
//    completionHandler(UIBackgroundFetchResultNewData);
//}
//- (void)jumpToOther:(NSDictionary *)userInfo
//{
//    // 得到通知的内容
////    [LKPushSetModel pushWithInfo:userInfo];
//}
//
//// 添加处理APNs通知回调方法
//#pragma mark- JPUSHRegisterDelegate
//// iOS 10 Support
//// iOS 10 在前台收到通知
//- (void)jpushNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(NSInteger))completionHandler {
//    // Required
//    NSDictionary * userInfo = notification.request.content.userInfo;
//
//    if (@available(iOS 10.0, *)) {
//        if([notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) {
//            [JPUSHService handleRemoteNotification:userInfo];
//        }
//    } else {
//        // Fallback on earlier versions
//    }
//    if (@available(iOS 10.0, *)) {
//        completionHandler(UNNotificationPresentationOptionAlert);
//    } else {
//        // Fallback on earlier versions
//    } // 需要执行这个方法，选择是否提醒用户，有Badge、Sound、Alert三种类型可以选择设置
//}
//
//
//// iOS 10 Support
//// App通知的点击事件
//- (void)jpushNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)(void))completionHandler {
//
//    // Required
//    NSDictionary * userInfo = response.notification.request.content.userInfo;
//    [self jumpToOther:userInfo];
//
//    if (@available(iOS 10.0, *)) {
//        if([response.notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) {
//            [JPUSHService handleRemoteNotification:userInfo];
//        }
//    } else {
//        // Fallback on earlier versions
//    }
//    completionHandler();  // 系统要求执行这个方法
//}
//
//
//// 当客户端注册远程通知时，如果成功，则回调第一个，客户端把deviceToken取出来发给服务端，push消息的时候要用。
//- (void)application:(UIApplication *)application
//didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
//
////    [LKPushSetModel setUpMyPushInfo];
//    [JPUSHService registerDeviceToken:deviceToken];
//}
//
//- (void)applicationDidEnterBackground:(UIApplication *)application
//{
//    /*
//     Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
//     If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
//     */
//    [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:nil];
//}

#pragma mark - UISceneSession lifecycle


//- (UISceneConfiguration *)application:(UIApplication *)application configurationForConnectingSceneSession:(UISceneSession *)connectingSceneSession options:(UISceneConnectionOptions *)options {
//    // Called when a new scene session is being created.
//    // Use this method to select a configuration to create the new scene with.
//    return [[UISceneConfiguration alloc] initWithName:@"Default Configuration" sessionRole:connectingSceneSession.role];
//}
//
//
//- (void)application:(UIApplication *)application didDiscardSceneSessions:(NSSet<UISceneSession *> *)sceneSessions {
//    // Called when the user discards a scene session.
//    // If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions.
//    // Use this method to release any resources that were specific to the discarded scenes, as they will not return.
//}


@end
